package com.well.register.console.aop;

import com.well.register.console.util.RpcResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @description:
 */
@Slf4j
@RestControllerAdvice
public class WellExceptionHandler {

  /**
   * 处理AwesomeException
   *
   * @param e
   * @param request
   * @param response
   * @return
   */
  @ExceptionHandler(WellException.class)
  public RpcResponse handleAwesomeException(WellException e, HttpServletRequest request, HttpServletResponse response) {
    e.printStackTrace();
    return RpcResponse.fail(e.getCode(), e.getMsg());
  }


  /**
   * 专门针对运行时异常
   *
   * @param e
   * @return
   */
  @ExceptionHandler(RuntimeException.class)
  public RpcResponse handleRuntimeException(RuntimeException e) {
    e.printStackTrace();
    return RpcResponse.fail(500, e.getMessage());
  }
}